home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 April: Mac OS SDK / Dev.CD Apr 00 SDK1.toast / Development Kits / Hardware / PC Card SDKs / PC Card Manager 3.0 / AnotherCustomEnabler / IBMEthernet.c < prev    next >
Encoding:
Text File  |  1997-06-05  |  9.9 KB  |  356 lines  |  [TEXT/CWIE]

  1. //    ----------------------------------------------------------------------
  2. //
  3. //    Module:
  4. //        IBM OEM Ethernet.c
  5. //
  6. //    Purpose:
  7. //        This enabler is designed to correct the IBM OEM Ethernet PC Card. 
  8. //        The IBM OEM Ethernet card has a 1B tuple that instructs the PC Card 
  9. //        3.0 family to place the buffer memory at 11000 instead of 4000 where 
  10. //        it is located.  
  11. //
  12. //    Authors:
  13. //        Carl Fallis
  14. //
  15. //    Copyright:    © 1996 SystemSoft Corporation, all rights reserved.
  16. //    ----------------------------------------------------------------------
  17.  
  18. #define    FOR_SYSTEM7_AND_SYSTEM8_PREEMPTIVE    1
  19. #define    FOR_SYSTEM7_AND_SYSTEM8_DEPRECATED    1
  20.  
  21. #include <PCCardEnablerPlugin.h>
  22. #include <PCCardTuples.h>
  23. #include <Errors.h>
  24. #include <Devices.h>
  25. #include <DriverServices.h>
  26.  
  27. //#define DEBUG_ON 1
  28. #ifdef DEBUG_ON
  29. #define DebugMessage(x) SysBreakStr(x)
  30. #else
  31. #define DebugMessage(x)
  32. #endif
  33.  
  34. //----------------------------------------------------------------------
  35.  
  36. #define kIBMOEMEthernet        0x0a4000200
  37.  
  38. #define kManifID            0x0a400
  39. #define kManifInfo            0x00200
  40.  
  41. const unsigned char kIBM1BBadData[] = {0xC1,0x81,0x7E,0x19,0x55,0x15,
  42.                                               0x26,0x01,0x0E,0xFC,0x33,0x45,0x70,
  43.                                               0xFF,0xFF,0x48,0x40,0x10,0x01};
  44.                                               
  45. const unsigned char kIBM1BGoodData[] = {0xC1,0x81,0x7E,0x19,0x55,0x15,
  46.                                               0x26,0x01,0x0E,0xFC,0x33,0x45,0x70,
  47.                                               0xFF,0xFF,0x48,0x40,0x40,0x00};
  48.  
  49.  
  50. //----------------------------------------------------------------------
  51. //    Local Prototypes
  52.  
  53. typedef PCCardTupleIterator PCCardTupleIteratorPtr;
  54.  
  55. OSStatus MyValidateHardware(const RegEntryID * lpCardEntry);
  56. OSStatus MyGetFirstTuple(UInt32 socket, UInt32 device, PCCardTupleIteratorPtr lpTupleIterator,
  57.             Byte desiredTuple, void *lptupleData, UInt32 *lpTupleBufferSize, Byte *lpFoundTuple);
  58. OSStatus MyGetNextTuple(PCCardTupleIteratorPtr tupleIterator, Byte desiredTuple, void *tupleData, ByteCount *tupleBufferSize, Byte *foundTuple);
  59.  
  60.  
  61. OSStatus _IdentifyCard(const RegEntryID *    lpCardEntry);
  62. Boolean CheckVers1Tuple(unsigned char * data, char * manufacturerName, char * cardName);
  63.  
  64. //----------------------------------------------------------------------
  65. // Globals
  66.  
  67. #define kVersionMajor        1
  68. #define kVersionMinor        0
  69. #define kVersionStage        developStage
  70. #define kVersionNonRel        1
  71. #define kPluginNamePString    "\ppccarda4,2"
  72.  
  73. #pragma export on 
  74.  
  75. // --------------------
  76. // Here's the exported Driver Descriptor
  77. DriverDescription TheDriverDescription = {
  78.     /*
  79.      * Signature info
  80.      */
  81.     kTheDescriptionSignature,                /* OSType driverDescSignature            */
  82.     kInitialDriverDescriptor,                /* DriverDescVersion driverDescVersion    */
  83.     /*
  84.      * DriverType driverType - these are defined in
  85.      */
  86.     kPluginNamePString,                        /* Name of hardware */
  87.     kVersionMajor, kVersionMinor,            /* NumVersion version */
  88.     kVersionStage, kVersionNonRel,
  89.  
  90.     /*
  91.      * DriverOSRuntime driverOSRuntimeInfo
  92.      */
  93.     kDriverIsLoadedUponDiscovery    |    /* Loader runtime options                */
  94.     kDriverIsUnderExpertControl,        /* I/O expert handles loads/opens        */
  95.     kPluginNamePString,                    /* Str31 driverName    (OpenDriver param)    */
  96.     0, 0, 0, 0, 0, 0, 0, 0,                /* UInt32 driverDescReserved[8]            */
  97.  
  98.     /*
  99.      * DriverOSService Information. This section contains a vector count followed by
  100.      * a vector of structures, each defining a driver service.
  101.      */
  102.     1,                                        /*     ServiceCount nServices                */
  103.  
  104.     /*
  105.      * DriverServiceInfo service[0]
  106.      */
  107.     kServiceCategoryPCCard,                    /* OSType serviceCategory                */
  108.     kServiceTypePCCardEnabler,                /* OSType serviceType                    */
  109.  
  110.     1, 0,developStage, 1
  111.     };
  112.  
  113.  
  114. // --------------------
  115. // Here's the exported Plugin Function Table…
  116. PCCardEnablerPluginDispatchTable ThePluginDispatchTable =
  117. {
  118.     /* PCCardEnablerPluginHeader */
  119.     { kPCCardEnablerPluginCurrentVersion, 0, 0, 0 },
  120.  
  121.     /* CEValidateHardwareProc            */        MyValidateHardware,
  122.     /* CEInitializeProc                    */    CEInitializeCard,
  123.     /* CECleanupProc                    */    CEFinalizeCard,
  124.     /* CEPowerManagementProc            */    CEPowerManagement,
  125.  
  126.     /* CEHandleEventProc                */    CEHandleCardEvent,
  127.     /* CEGetCardInfoProc                */    CEGetCardInfo,
  128.     /* CEAddCardPropertiesProc            */    CEAddCardProperties,
  129.     /* CEGetDeviceCountProc                */    CEGetDeviceCount,
  130.  
  131.     /* CEGetDeviceNameProc                */    CEGetDeviceName,
  132.     /* CEGetDeviceCompatibleNameProc    */    CEGetDeviceCompatibleNames,
  133.     /* CEGetDeviceTypeProc                */    CEGetDeviceType,
  134.     /* CEGetDeviceTypeNameProc            */    CEGetDeviceTypeName,
  135.     /* CEAddDevicePropertiesProc        */    CEAddDeviceProperties,
  136.     /* CEConfigureDeviceProc            */    CEConfigureDevice,
  137.     /* CEFinalizeDeviceProc                */    CEFinalizeDevice,
  138.  
  139.     /* CEValidateCISProc                */    CEValidateCIS,
  140.     /* CEGetFirstTupleProc                */        MyGetFirstTuple,
  141.     /* CEGetNextTupleProc                */        MyGetNextTuple,
  142.  
  143.     /* InterruptHandler                    */    CEDefaultInterruptHandler,
  144.     /* InterruptEnabler                    */    NULL,
  145.     /* InterruptDisabler                */    NULL
  146. };
  147.  
  148. #pragma export off
  149.  
  150. //----------------------------------------------------------------------
  151. //    Determine whether the plugin can support this card. 
  152. //  Returning noErr means that the card is supported
  153. OSStatus MyValidateHardware(const RegEntryID *lpCardEntry)
  154. {
  155.     OSStatus             err;
  156.     
  157. //    DebugStr("\pCustomCardEnabler:  MyValidateHardware");
  158.     if (!(lpCardEntry)) return(paramErr);
  159.  
  160.     // see if we are supposed to handle this card, set global card id
  161.     err = _IdentifyCard(lpCardEntry);
  162.  
  163. #ifdef DEBUG_ON
  164.     if (err == noErr) DebugMessage("\pIBM OEM Ethernet Enabler will handle this card!;g");
  165. #endif
  166.     return(err);
  167. }
  168.  
  169.  
  170. //----------------------------------------------------------------------
  171. //    Look to see if this is a card we are supposed to handle
  172. //    If it is return noErr, other wise return kUnsupportedCardErr
  173. // 
  174. // Identification of the IBM OEM Ethernet card 
  175. //    1) check the manufacturer's ID
  176. //    2) check the vers 1 for IBM Corp Ethernet
  177. //    3) check for the config table entry for the bad entry so that we are sure that 
  178. //       this is the correct card we say it is our card
  179. OSStatus _IdentifyCard(const RegEntryID *lpCardEntry)
  180. {
  181.     PCCardTupleIteratorPtr     iter;
  182.     OSStatus                err = noErr;
  183.     unsigned char             tuple[MAX_TUPLE_SIZE];
  184.     UInt32                    size=MAX_TUPLE_SIZE, socket, device;
  185.     Byte                    foundTuple;
  186.     Boolean                    match = false; 
  187.     int                        i=0;
  188.     
  189.     
  190. //    DebugStr("\pCustomCardEnabler:  _IdentifyCard");
  191.     if(!(lpCardEntry)  ) return(paramErr);
  192.  
  193.     err =  CEGetSocketAndDeviceFromRegEntry(lpCardEntry, &socket, &device);
  194.     if (err != noErr)
  195.         return(err);                            
  196.  
  197.     iter = PCCardNewTupleIterator();
  198.     if (iter == NULL)
  199.         return memFullErr;
  200.  
  201.     err = CECompareCISTPL_MANFID(lpCardEntry, 
  202.                                     kManifID,
  203.                                     kManifInfo,
  204.                                     &match); 
  205.         
  206.         
  207.     if ((err != noErr) || (match != true))
  208.         goto CLEAN_ERROR_EXIT;
  209.                                         
  210.     // step one passed now check the vers 1 using the built in CheckVers1Tuple call
  211.         
  212.     err = CSGetFirstTuple(socket, device, iter, CISTPL_VERS_1, &tuple, &size, &foundTuple);
  213.         
  214.     if ((err != noErr) && (foundTuple == CISTPL_VERS_1))
  215.         goto CLEAN_ERROR_EXIT;
  216.  
  217.         
  218.     if ( !CheckVers1Tuple(&tuple[0], "IBM Corp.", "Ethernet") )
  219.         goto CLEAN_ERROR_EXIT;
  220.         
  221.         
  222.     // we made it this far lets see if the touple is incoorect
  223.     err = CSGetFirstTuple(socket, device, iter, CISTPL_CFTABLE_ENTRY, &tuple, &size, &foundTuple);
  224.  
  225.     if (err != noErr)
  226.         goto CLEAN_ERROR_EXIT;
  227.                 
  228.     // compare the Table entry with the known bad entry to make sure that this is the card
  229.         
  230.     match = true;
  231.     for (i=0;i < sizeof(kIBM1BBadData); i++)
  232.     {
  233.         if (tuple[i] != kIBM1BBadData[i])
  234.         {
  235.             match = false;
  236.             continue;
  237.         }
  238.     }
  239.  
  240.     if (match)    // this is the card !
  241.     {
  242.         (void) PCCardDisposeTupleIterator(iter);
  243.         return(noErr);
  244.     }
  245.         
  246.         
  247.     
  248.     
  249. CLEAN_ERROR_EXIT:    
  250.         
  251.     (void) PCCardDisposeTupleIterator(iter);
  252.     return(kUnsupportedCardErr);
  253.                         
  254. }
  255.  
  256.  
  257.  
  258.  
  259. //----------------------------------------------------------------------
  260. OSStatus MyGetFirstTuple(UInt32 socket, UInt32 device,            
  261.                                 PCCardTupleIteratorPtr lpTupleIterator,
  262.                                 Byte desiredTuple,             
  263.                                 void *lpTupleData,
  264.                                 UInt32 *lpTupleBufferSize,
  265.                                 Byte *lpFoundTuple)
  266. {
  267.     OSStatus                 err = noErr;
  268.     unsigned char            *dataPtr = (unsigned char *)lpTupleData;
  269.     UInt32                    i=0;
  270.  
  271.     
  272. //    DebugStr("\pCustomCardEnabler:  MyGetFirstTuple");        
  273.     if(!(lpTupleIterator && lpFoundTuple && lpTupleData && *lpTupleBufferSize))
  274.         return(paramErr);
  275.     
  276.     
  277.     
  278.     err = CSGetFirstTuple(socket, device,lpTupleIterator,desiredTuple,
  279.                                 lpTupleData,lpTupleBufferSize,lpFoundTuple);
  280.     
  281.     
  282.  
  283.     if (*lpFoundTuple == CISTPL_CFTABLE_ENTRY)
  284.     {
  285. //        for (i=0;i< *lpTupleBufferSize;i++)
  286. //                dataPtr[i] = (unsigned char)kIBM1BGoodData[i];
  287.         dataPtr[17] = kIBM1BGoodData[17];
  288.         dataPtr[18] = kIBM1BGoodData[18];
  289.     }        
  290.     return(err);
  291. }            
  292.  
  293. //
  294. // MyGetNextTuple 
  295. //            
  296. OSStatus MyGetNextTuple(PCCardTupleIteratorPtr lpTupleIterator, 
  297.                         Byte desiredTuple, 
  298.                         void *lpTupleData, 
  299.                         ByteCount *lpTupleBufferSize, 
  300.                         Byte *lpFoundTuple)
  301. {
  302.     OSStatus                 err = noErr;
  303.     unsigned char            *dataPtr = (unsigned char *)lpTupleData;
  304.     UInt32                    i=0;
  305.     
  306.     
  307. //    DebugStr("\pCustomCardEnabler:  MyGetNextTuple");        
  308.     if(!(lpTupleIterator && lpFoundTuple && lpTupleData && *lpTupleBufferSize))
  309.         return(paramErr);
  310.     
  311.     
  312.     
  313.     err = CSGetNextTuple(lpTupleIterator, desiredTuple,lpTupleData,lpTupleBufferSize,
  314.                                 lpFoundTuple);
  315.     
  316.     
  317.     if (*lpFoundTuple == CISTPL_CFTABLE_ENTRY)
  318.     {
  319. //        for (i=0;i< *lpTupleBufferSize;i++)
  320. //                dataPtr[i] = kIBM1BGoodData[i];
  321.     
  322.         // change the last two bytes of the tuple to x04000
  323.         dataPtr[17] = kIBM1BGoodData[17];
  324.         dataPtr[18] = kIBM1BGoodData[18];
  325.     }    
  326.     return(err);
  327. }                        
  328.  
  329.  
  330. //----------------------------------------------------------------------
  331. //     Pass in a VERS1 tuple and check that the manufacturer name and card name are
  332. // the the same as the ones passed in
  333. Boolean CheckVers1Tuple(unsigned char * data, char * manufacturerName, char * cardName)
  334. {
  335.     unsigned char          *ptr;
  336.     
  337.     
  338. //    DebugStr("\pCustomCardEnabler:  CheckVers1Tuple");
  339.     // the manufacturer name is a null terminated string starting in byte three
  340.     ptr = &(data[2]);
  341.     if(CStrCmp((const char *) ptr, manufacturerName) == 0)
  342.     { 
  343.         // the card name is a null terminated string that starts after the manufacturer name
  344.         while(*ptr++)
  345.             ;
  346.         if(CStrCmp((const char *) ptr, cardName) != 0)
  347.             return(false);
  348.     }
  349.     else
  350.         return(false);                            
  351.     
  352.     // if we make it to here, both names match
  353.     return(true);
  354. }
  355.  
  356.